// pages/user/index/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    isLogin: false,
    showDialog: false,
    list: [{
        name: "修改密码",
        url: "../editInfo/editInfo",
        icon: "icon-xiugai",
        openType: "navigate",
        requireLogin: true,
        bindtap: "toShowDialog"
      },
      {
        name: "绑定微信",
        url: "../bindWechat/bindWechat",
        icon: "icon-binding02",
        openType: "navigate",
        requireLogin: true,
        bindtap: "toShowDialog"
      },
      {
        name: "扫描记录",
        url: "../../record/index/index",
        icon: "icon-lianxijilu",
        openType: "switchTab",
        bindtap: "toShowDialog"
      },
      {
        name: "用户反馈",
        url: "../feedback/feedback",
        icon: "icon-fankui",
        openType: "navigate",
        bindtap: "toShowDialog"
      },
      {
        name: "关于我们",
        url: "../aboutUs/aboutUs",
        icon: "icon-guanyu",
        openType: "navigate"
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    // 加载用户信息
    this.setData({
      userInfo: app.globalData.userInfo,
      isLogin: app.globalData.isLogin
    })

  },

  logout(res) {
    app.logout()
  },

  toLogin() {
    wx.navigateTo({
      url: '../../login/index/index',
    })
  },


  toShowDialog() {
    if (!this.data.isLogin) {
      this.setData({
        showDialog: true
      });
    }
  },
  onClose() {
    this.setData({
      showDialog: false
    });
  },
  onConfirm() {
    this.setData({
      showDialog: false
    });
    this.toLogin();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})